import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/ui/draw_under_line.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 评价详情
///
class EvaluateInfo extends StatefulWidget {
  const EvaluateInfo({Key? key}) : super(key: key);

  @override
  State<EvaluateInfo> createState() => _EvaluateInfoState();
}

class _EvaluateInfoState extends State<EvaluateInfo> {
  List<String> urls = [
    'https://img1.baidu.com/it/u=3033226715,2238019049&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500',
    'https://img0.baidu.com/it/u=2718980415,581692139&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500',
    'https://img2.baidu.com/it/u=3308284036,3855849897&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800',
    'https://img2.baidu.com/it/u=4109695418,2044247650&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500'
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: ToolsUtils.getDefaultBrnAppBar('评价详情'),
      body: SingleChildScrollView(
        padding: const EdgeInsets.symmetric(horizontal: Sizes.default20),
        child: Column(
          children: [
            DrawUnderLine(
              color: ColorsUtils.parseColorFromHexString('#D7D7D7'),
              child: Container(
                padding: const EdgeInsets.symmetric(vertical: Sizes.default20),
                child: ListBody(
                  children: [
                    Container(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '订单编号：12232964103521',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    ),
                    Container(
                      margin: const EdgeInsets.symmetric(vertical: Sizes.default20),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '店铺名称：默林如斯的肠粉店',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    ),
                    Container(
                      margin: const EdgeInsets.only(bottom: Sizes.default20),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '顾客昵称：Z**13',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    ),
                    Container(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '配送员：王小品',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            DrawUnderLine(
              color: ColorsUtils.parseColorFromHexString('#D7D7D7'),
              child: Container(
                padding: const EdgeInsets.symmetric(vertical: Sizes.default20),
                child: ListBody(
                  children: [
                    Row(
                      children: [
                        Text(
                          '商家：',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                        ),
                        BrnRatingStar(
                            count: 5,
                            selectedCount: 3.5,
                            space: 3,
                            canRatingZero: true,
                            starBuilder: (RatingState state) {
                              return buildRating(state);
                            }),
                        const SizedBox(
                          width: Sizes.default10,
                        ),
                        Text(
                          '味道4星　包装5星',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                        )
                      ],
                    ),
                    Container(
                      margin: const EdgeInsets.only(top: Sizes.default20),
                      child: Row(
                        children: [
                          Text(
                            '配送服务：',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                          ),
                          BrnRatingStar(
                              count: 5,
                              selectedCount: 4.5,
                              space: 3,
                              canRatingZero: true,
                              starBuilder: (RatingState state) {
                                return buildRating(state);
                              }),
                        ],
                      ),
                    )
                  ],
                ),
              ),
            ),
            DrawUnderLine(
              color: ColorsUtils.parseColorFromHexString('#D7D7D7'),
              child: Container(
                padding: const EdgeInsets.symmetric(vertical: Sizes.default20),
                child: ListBody(
                  children: [
                    Container(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '推荐商品：口水鸡',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    ),
                    Container(
                      margin: const EdgeInsets.symmetric(vertical: Sizes.default20),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '点踩商品：清水白菜',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    ),
                    Container(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '评价内容：服务好，上菜快，口味一流！',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    ),
                    Container(
                      alignment: Alignment.centerLeft,
                      margin: const EdgeInsets.symmetric(vertical: Sizes.default20),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '评价图片：',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                            ),
                          ),
                          Expanded(
                              child: Container(
                            alignment: Alignment.centerLeft,
                            child: Wrap(
                              spacing: Sizes.default10,
                              runSpacing: Sizes.default12,
                              children: urls
                                  .map((e) => GFImageOverlay(
                                        width: Sizes.default80,
                                        height: Sizes.default80,
                                        borderRadius: BorderRadius.circular(Sizes.default5),
                                        image: NetworkImage(e),
                                      ))
                                  .toList(),
                            ),
                          ))
                        ],
                      ),
                    ),
                    Container(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '评价时间：2021-12-03 16:41:40',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    )
                  ],
                ),
              ),
            ),
            Container(
              alignment: Alignment.centerLeft,
              margin: const EdgeInsets.symmetric(vertical: Sizes.default20),
              child: Text(
                '商家回复：感谢亲的惠顾！',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
              ),
            ),
            Container(
              alignment: Alignment.centerLeft,
              child: Text(
                '回复时间：2021-12-03 22:11:43',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget buildRating(RatingState state) {
    switch (state) {
      case RatingState.select:
        return BrunoTools.getAssetSizeImage(BrnAsset.iconStar, Sizes.default15, Sizes.default15,
            color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6));
      case RatingState.half:
        return BrunoTools.getAssetSizeImage(BrnAsset.iconStarHalf, Sizes.default15, Sizes.default15,
            color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6));
      case RatingState.unselect:
      default:
        return BrunoTools.getAssetSizeImage(BrnAsset.iconStar, Sizes.default15, Sizes.default15,
            color: ColorsUtils.parseColorFromHexString('#A6A6A6'));
    }
  }
}
